package impls.agents.dialogs;

import impls.classes.Launcher;

import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JDialog;

public class PathChooseDialog extends JDialog implements ActionListener {

	private static final long serialVersionUID = -3013072409317061171L;

	private Launcher owner;

	private TextField fuel;

	public PathChooseDialog(Launcher owner) {
		super(owner);
		this.owner = owner;
		this.setModal(true);
		this.setResizable(false);
		this.setLayout(new FlowLayout());
		this.setTitle("Path Chooser");

		fuel = new TextField(owner.getPath());
		fuel.setColumns(30);

		this
				.getContentPane()
				.add(
						new Label(
								"Please enter the correct path to the .class files:"));
		this.getContentPane().add(fuel);

		Button next = new Button("Ok");
		next.addActionListener(this);

		this.getContentPane().add(next);

		Button cancel = new Button("Cancel");
		cancel.addActionListener(this);

		this.getContentPane().add(cancel);

		pack();
		this.setVisible(true);
	}

	public void actionPerformed(ActionEvent e) {
		if (e.getActionCommand().equals("Cancel")) {
			this.dispose();
		}

		if (e.getActionCommand().equals("Ok")) {
			owner.setPath(fuel.getText());
			this.dispose();
		}

	}

}
